﻿package mortal.game.view.mainUI.smallMap.view
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gLinkText.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.ai.ais.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.smallMap.view.data.*;
    import mortal.game.view.mainUI.smallMap.view.render.*;
    import mortal.mvc.core.*;

    public class SmallMapTypeShower extends GSprite
    {
        private var _typeItems:Array;
        private var _nameTexts:Array;
        private var _iconContainer:GSprite;
        private var _nameContainer:GSprite;
        private var _targetBootContainer:GSprite;
        protected var _btnFlyBoot:FlyBoot;

        public function SmallMapTypeShower()
        {
            this._typeItems = [];
            this._nameTexts = [];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._iconContainer = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this._iconContainer.mouseChildren = true;
            this._iconContainer.mouseEnabled = true;
            this.addChild(this._iconContainer);
            this._nameContainer = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this._nameContainer.mouseChildren = false;
            this._nameContainer.mouseEnabled = false;
            this.addChild(this._nameContainer);
            this._targetBootContainer = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this.addChild(this._targetBootContainer);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:Array = null;
            super.disposeImpl(param1);
            if (this._typeItems.length > 0)
            {
                for each (_loc_2 in this._typeItems)
                {
                    
                    DisplayUtil.delNotUse(_loc_2, 0);
                }
                this._typeItems = [];
            }
            if (this._nameTexts.length > 0)
            {
                for each (_loc_2 in this._nameTexts)
                {
                    
                    DisplayUtil.delNotUse(_loc_2, 0);
                }
                this._nameTexts = [];
            }
            this._nameContainer.dispose(param1);
            this._nameContainer = null;
            this._iconContainer.dispose(param1);
            this._iconContainer = null;
            this._targetBootContainer.dispose(param1);
            this._targetBootContainer = null;
            if (this._btnFlyBoot != null)
            {
                this._btnFlyBoot.dispose(param1);
                this._btnFlyBoot = null;
            }
            return;
        }// end function

        public function showFlyBoot(param1:int, param2:Boolean = false, param3:int = 0, param4:int = 0) : void
        {
            if (!FlyBootAI.checkCanFly(param1, false))
            {
                DisplayUtil.removeMe(this._btnFlyBoot);
                return;
            }
            if (!param2)
            {
                DisplayUtil.removeMe(this._btnFlyBoot);
            }
            else
            {
                if (this._btnFlyBoot == null)
                {
                    this._btnFlyBoot = UICompomentPool.getUICompoment(FlyBoot) as FlyBoot;
                    this.addChild(this._btnFlyBoot);
                    this._btnFlyBoot.configEventListener(MouseEvent.CLICK, this.flyHandler);
                }
                this._btnFlyBoot.x = param3 - this._btnFlyBoot.width / 2 - 2;
                this._btnFlyBoot.y = param4 - this._btnFlyBoot.height + 2;
                this._targetBootContainer.addChild(this._btnFlyBoot);
            }
            return;
        }// end function

        public function showTargetPoint(param1:Boolean = false, param2:int = 0, param3:int = 0) : void
        {
            return;
        }// end function

        private function flyHandler(event:MouseEvent) : void
        {
            if (this._btnFlyBoot == null)
            {
                return;
            }
            var _loc_2:* = new SPoint();
            _loc_2.x = this._btnFlyBoot.x + this._btnFlyBoot.width / 2 + 2;
            _loc_2.y = this._btnFlyBoot.y + this._btnFlyBoot.height - 2;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapFlybootReq, _loc_2));
            return;
        }// end function

        public function updateTypeShow(param1:int, param2:Number, param3:Array) : void
        {
            var _loc_8:SmallMapTypeIconData = null;
            var _loc_9:SmallMapTypeIconItem = null;
            var _loc_10:GTextFiled = null;
            var _loc_11:GTextFormat = null;
            if (param3 == null)
            {
                return;
            }
            var _loc_4:* = this._typeItems[param1];
            var _loc_5:* = this._nameTexts[param1];
            if (_loc_4 == null)
            {
                _loc_4 = [];
                _loc_5 = [];
                this._typeItems[param1] = _loc_4;
                this._nameTexts[param1] = _loc_5;
            }
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            while (_loc_7 < param3.length)
            {
                
                _loc_8 = param3[_loc_7];
                _loc_9 = _loc_4[_loc_7];
                if (_loc_9 == null)
                {
                    _loc_9 = UICompomentPool.getUICompoment(SmallMapTypeIconItem) as SmallMapTypeIconItem;
                    _loc_4.push(_loc_9);
                    this._iconContainer.addChild(_loc_9);
                }
                _loc_8.scale = param2;
                _loc_9.updateData(_loc_8);
                if (_loc_8.name != "")
                {
                    _loc_10 = _loc_5[_loc_6];
                    if (_loc_10 == null)
                    {
                        _loc_11 = GlobalStyle.textFormatPutong;
                        _loc_11.align = TextFormatAlign.CENTER;
                        _loc_11.size = 12;
                        _loc_10 = UIFactory.gTextField("", 0, 0, 100, 20, this._nameContainer, _loc_11);
                        _loc_5.push(_loc_10);
                    }
                    _loc_10.htmlText = _loc_8.name;
                    _loc_10.x = _loc_9.labelX;
                    _loc_10.y = _loc_9.labelY;
                    if (_loc_8.isGrayFilter)
                    {
                        _loc_10.textColor = GlobalStyle.colorHuiUint;
                    }
                    else
                    {
                        _loc_10.textColor = GlobalStyle.colorPutongUint;
                    }
                    _loc_6++;
                }
                _loc_7++;
            }
            DisplayUtil.delNotUse(_loc_4, _loc_7);
            DisplayUtil.delNotUse(_loc_5, _loc_6);
            return;
        }// end function

        public function isShowName(param1:Boolean) : void
        {
            this._nameContainer.visible = param1;
            return;
        }// end function

    }
}
